import type { Order, OrderQuery, UpdateOrderRequest } from './model';

import type { ID, PageResult } from '#/api/common';

import { requestClient } from '#/api/request';

enum Api {
  cancelOrder = '/order/v1/cancelOrder',
  orderExport = '/order/v1/export',
  orderList = '/order/v1/orderPage',
  orderRefund = '/order/v1/orderRefund',
  updateOrderInfo = '/order/v1/updateOrderInfo',
}

/**
 * 订单分页列表
 * @param data 请求参数
 * @returns 列表
 */
export function orderList(
  data?: OrderQuery & { pageNo?: number; pageSize?: number },
) {
  return requestClient.post<PageResult<Order>>(Api.orderList, data);
}

/**
 * 修改订单预约状态
 * @param data 参数
 */
export function updateOrderInfo(data: UpdateOrderRequest) {
  return requestClient.get<void>(`${Api.updateOrderInfo}`, {
    params: data,
  });
}

/**
 * 取消订单
 * @param orderId 订单ID
 */
export function cancelOrder(orderId: ID) {
  return requestClient.get<void>(`${Api.cancelOrder}`, {
    params: {
      orderId,
    },
  });
}

/**
 * 订单退款
 * @param orderId 订单ID
 */
export function orderRefund(orderId: ID) {
  return requestClient.get<void>(`${Api.orderRefund}`, {
    params: {
      orderId,
    },
  });
}

/**
 * 导出订单
 * @param data 请求参数
 */
export function orderExport(
  data?: OrderQuery & { pageNo?: number; pageSize?: number },
) {
  return requestClient.post<Blob>(Api.orderExport, data, {
    data,
    isTransformResponse: false,
    responseType: 'blob',
  });
}
